<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
cfc('core')->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$return['basic']=$this->plugin_setting('basic');
if($_RQ['op']=='main'){
    $member=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','groupid','avatar','nickname'));
	if(!member){
		exi('找不到会员信息！','error');
	}
	$user_id=pdo_getcolumn('jy_zhongchou_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');
	if(!$user_id){
		$insert=array(
			'mid'=>$_SESSION['uid'],
			'uniacid'=>$_SESSION['uniacid'],
			'tel'=>$member['mobile'],
			'nickname'=>$member['nickname'],
			'avatar'=>$member['avatar'],
			'createtime'=>TIMESTAMP,
		);
		pdo_insert('jy_zhongchou_member',$insert);
	}
	$user=pdo_get('jy_zhongchou_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$return['member']=$member;
	$return['user']=$user;
	$return['item']=array();
	exi($return);
}
//修改用户信息
if($_RQ['op']=='set'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		$data=array(
			'nickname'=>$postdata['nickname'],
			'avatar'=>$postdata['avatar'],
			'tel'=>$postdata['tel'],
		);
		$user_id=pdo_getcolumn('jy_zhongchou_member',array('mid'=>$_SESSION['uid']),'id');		
		if($user_id){
			pdo_update('jy_zhongchou_member',$data,array('id'=>$_SESSION['uid']));
			exi('修改成功','','jy_zhongchou/home/');		 
		}
	}
	$user=pdo_get('jy_zhongchou_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$member=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$return['item']=$user;
	$return['member']=$member;
	exi($return);
	}

//我的提现记录
if($_RQ['op']=='cashrecord'){
	$params=array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']);
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['status']=$_RQ['status'];
	}
	$list=pdo_getall('jy_zhongchou_cashrecord',$params);
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['overtime']=date('Y-m-d H:i:s',$item['overtime']);
		}
	}
	$return['list']=$list;
	exi($return);
}

//申请提现
if($_RQ['op']=='tixian'){
	$post=array();
	$post['money']=0;
	 $user=pdo_get('jy_zhongchou_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	if($_RQ['postdata']){
	   $postdata=get_postdata();
	   $money=$postdata['money'];
	   //被拉黑用户无法提现
	   if($user['status']==1){
		   exi('您已进入黑名单,无法提现，请联系管理员','error');
	   }
	   if(!$money||$money<=0){
		   exi('提现金额不规范，请重新填写提现金额','error');
	   }
	   if($money>$user['cash']){
		   exi('提现金额不得大于可提现金额，请重新填写提现金额','error');
	   }
	   //创建一个状态为正在申请的提现记录
	   $insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'money'=>$money,
			'status'=>0,
			'ordersn'=>get_ordersn('jy_vote_cashrecord','ordersn'),
			'createtime'=>TIMESTAMP
	   );
	   pdo_insert('jy_vote_cashrecord',$insert);
	   //修改用户可提现金额
	   pdo_update('jy_vote_user',array('cash'=>$user['cash']-$money),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	   exi('申请提现成功！','success','jy_vote/home/cashrecord/');
	
}
     $return['post']=$post;
     $return['user']=$user;
	 exi($return);
}